#include <cstdio>

#ifdef DEBUG
#define debug(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__);
#else
#define debug(fmt, ...) {}
#endif

typedef unsigned long long int uint;


inline uint fast_exp (uint b, uint e, uint m)
{
	uint x = 1;
	debug("\t%llu ^ %llu * %llu\t(mod %llu)\n", b, e, x, m);

	b %= m;
	debug("\t%llu ^ %llu * %llu\t(mod %llu)\n", b, e, x, m);
	while (b > 1 && e > 1)
	{
		switch (e % 2)
		{
			case 1:
			{
				x *= b;
				x %= m;
			}
			case 0:
			{
				b *= b;
				b %= m;
				e /= 2;
			}
		}
		debug("\t%llu ^ %llu * %llu\t(mod %llu)\n", b, e, x, m);
	}

	if (b == 0)
		return 0;

	if (e) {
		b *= x;
		b %= m;
		return b;
	}
	else
		return x;
}


int main ()
{
	uint b, e, m;

	while (scanf("%llu %llu %llu", &b, &e, &m) == 3)
	{
		printf("%llu\n", fast_exp(b,e,m));
	}

	return 0;
}